Flutter Navigator Route _RouteLifecycle
Route has a state machine.
The _RouteLifecycle
enum in Flutter defines the various states a route can be in throughout its lifecycle within the navigator. These states can be broadly categorized into three groups:
- routes that are present
- routes that are not present
- routes that are in transition.
Routes that are Present
-
staging
: Awaiting decision from the transition delegate. -
add
: Route is created byonGenerateInitialRoutes
or initialwidget.pages
. -
adding
: Waiting for completion of the future fromdidPush
of the top-most route. -
push
: Route added viapush()
and similar methods. -
pushReplace
: Route added viapushReplace()
and similar methods. -
pushing
: Waiting for the future fromdidPush
to complete. -
replace
: Route added viareplace()
and similar methods. -
idle
: Route is inactive but present.
Routes that are not Present
-
pop
: Preparing to calldidPop
. -
complete
: Preparing to calldidComplete
. -
remove
: Preparing to rundidReplace
/didRemove
. -
popping
: Waiting for the route to callfinalizeRoute
before transitioning todispose
. -
removing
: Waiting for subsequent routes to finish animating before transitioning todispose
.
Routes in Transition or Removed
-
dispose
: Preparing to dispose of the route. -
disposed
: The route has been disposed.
This enum is crucial for managing the lifecycle of routes in the navigator, from their creation and active use to their eventual removal and disposal.
The soruce code comment as below:
// The _RouteLifecycle state machine (only goes down):
//
// [creation of a _RouteEntry]
// |
// +
// |\
// | \
// | staging
// | /
// |/
// +-+----------+--+-------+
// / | | |
// / | | |
// / | | |
// / | | |
// / | | |
// pushReplace push* add* replace*
// \ | | |
// \ | | /
// +--pushing# adding /
// \ / /
// \ / /
// idle--+-----+
// / \
// / +------+
// / | |
// / | complete*
// | | /
// pop* remove*
// / \
// / removing#
// popping# |
// | |
// [finalizeRoute] |
// \ |
// dispose*
// |
// |
// disposed
// |
// |
// [_RouteEntry garbage collected]
// (terminal state)
//
// * These states are transient; as soon as _flushHistoryUpdates is run the
// route entry will exit that state.
// # These states await futures or other events, then transition automatically.
本文作者:Maeiee
本文链接:Flutter Navigator Route _RouteLifecycle
版权声明:如无特别声明,本文即为原创文章,版权归 Maeiee 所有,未经允许不得转载!
喜欢我文章的朋友请随缘打赏,鼓励我创作更多更好的作品!